package main.java.FSMDE.validation.rules;

import java.util.ArrayList;
import java.util.List;

import main.java.FSMDE.models.Diagram;
import main.java.FSMDE.models.Interface;
import main.java.FSMDE.models.InterfaceGraphType;
import main.java.FSMDE.models.Transition;
import main.java.FSMDE.validation.IValidationEntry;


public class InterfaceShouldTriggerTransitionValidator implements IRulesValidator {

	@Override
	public Iterable<IValidationEntry> validate(Diagram diagram) {
		List<IValidationEntry> entries = new ArrayList<IValidationEntry>();
		boolean isolated;
		for (Interface inface : diagram.getInterfaces()) {
			
			isolated = true;
			for (Transition transition : diagram.getTransitions()){
				if(transition.getSource() != null && transition.getDestination() != null){
					if(transition.getSource().equals(inface) && (!transition.getDestination().equals(inface)) ){ //excluding reflexive transitions
						isolated = false;
					}
				}
			}
			//exception: Ending interface does not trigger interfaces.
			if(inface.getGraphType().equals(InterfaceGraphType.Ending_interface)) isolated = false;
			if(isolated) entries.add(new InterfaceShouldTriggerTransitionValidationEntry(diagram, inface));
		}
		
		return entries;
	}
}
